package com.jjrwa.component;

import javax.swing.*;
import java.awt.*;

public class BaseFrame {

    protected JFrame windowCenter(String title, JPanel jPanel) {
        return windowCenter(title, jPanel, null, JFrame.DISPOSE_ON_CLOSE);
    }

    protected JFrame windowCenter(String title, JPanel jPanel, Dimension frameSize) {
        return windowCenter(title, jPanel, frameSize, JFrame.DISPOSE_ON_CLOSE);
    }

    protected JFrame windowCenter(String title, JPanel jPanel, Dimension frameSize, int operation) {
        JFrame frame = new JFrame(title);
        frame.setContentPane(jPanel);
        frame.setDefaultCloseOperation(operation);
        frame.pack();
        if (frameSize != null) {
            frame.setSize(frameSize);
        }
        Dimension size = frame.getSize();
        int width = Toolkit.getDefaultToolkit().getScreenSize().width;
        int height = Toolkit.getDefaultToolkit().getScreenSize().height;
        frame.setBounds((int) (width - size.getWidth()) / 2,
                (int) (height - size.getHeight()) / 4, (int) size.getWidth(), (int) size.getHeight());
        frame.setVisible(true);
        frame.setAlwaysOnTop(true);
        return frame;
    }

}
